package com.babble.comment.controller;

import com.babble.comment.dto.QueryReportDTO;
import com.babble.comment.dto.ReportDTO;
import com.babble.comment.entity.Report;
import com.babble.comment.service.IReportService;
import com.babble.comment.vo.ReportVo;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springblade.common.constant.CommonConstant;
import org.springblade.core.tool.api.R;
import org.springframework.data.domain.Page;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Digits;

/**
 * 举报评论控制器
 *
 * @author wm
 */
@Validated
@RestController
@RequestMapping("report")
@RequiredArgsConstructor
@Api(value = "评论模块", tags = "评论接口")
public class ReportController {
	private final IReportService reportService;

	@PostMapping("create")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "添加评论", notes = "用户添加评论")
	public R<Report> create(@RequestBody @Validated ReportDTO reportDTO) {
		return R.data(reportService.create(reportDTO));
	}

	@GetMapping("list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "获取举报", notes = "分页获取评论的举报信息")
	public R<Page<ReportVo>> list(QueryReportDTO query) {
		return R.data(reportService.list(query));
	}

	@PutMapping("update/progress")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "更改状态", notes = "更改评论的举报信息状态")
	public R<Report> update(@RequestParam String id, @RequestParam @Digits(integer = 0, fraction = 2, message = "请选择合法状态") Integer progress) {
		return R.data(reportService.updateProgress(id, progress));
	}

	@DeleteMapping("delete/{id}")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "删除举报", notes = "删除评论的举报信息")
	public R delete(@PathVariable("id") String id) {
		reportService.delete(id);
		return R.success("删除成功！");
	}

}
